package com.huffman.smart_picture.handler;

import com.huffman.smart_picture.common.base.reponse.ResponseResult;
import com.huffman.smart_picture.common.exception.BusinessException;
import com.huffman.smart_picture.common.exception.ErrorEnum;
import com.huffman.smart_picture.common.exception.SystemException;
import com.huffman.smart_picture.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author DengLin
 * @title 统一异常处理
 */
//@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public ResponseResult handleRuntimeException(RuntimeException systemException) {
        log.error("RuntimeException:" + systemException.getMessage());
        return ResponseUtil.fail(ErrorEnum.SYSTEM_ERROR);
    }

    @ExceptionHandler(SystemException.class)
    public ResponseResult handleSystemException(SystemException systemException) {
        log.error("SystemException:" + systemException.getMessage() + "--" + systemException.getDescription());
        return ResponseUtil.fail(ErrorEnum.SYSTEM_ERROR);
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseResult handleBusinessException(BusinessException businessException) {
        log.error("BusinessException:" + businessException.getMessage() + "--" + businessException.getDescription());
        return ResponseUtil.fail(businessException.getCode(), businessException.getMessage(), businessException.getDescription());
    }

}
